namespace mvcincode.Middlewares;


public class RoutingTestMiddleware
{
    private readonly RequestDelegate _next;
    private readonly ILogger<RoutingTestMiddleware> _logger;

    public RoutingTestMiddleware(RequestDelegate next
        , ILogger<RoutingTestMiddleware> logger)
    {
        this._next = next;
        this._logger = logger;
    }

    public Task Invoke(HttpContext httpContext)
    {
        // 这个中间件只有放在MapControllerRoute中间件后面才能得到GetEndpoint的实例对象
        var endpoint = httpContext.GetEndpoint();
        _logger.LogInformation(endpoint?.DisplayName);
        
        return _next(httpContext);
    }
}